home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / walk.lua < prev   
Text File  |  2004-01-29  |  14KB  |  573 lines

  1. -- walk state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onEnter(function(msg)
  6.         setState("stand");
  7.     end )
  8.  
  9.     onReturn(function(msg)
  10.         nextAction();
  11.     end )
  12.         
  13.     onMsg("queue", function(msg)
  14.         nextAction();
  15.     end )                
  16.  
  17.     onMsg("waitForChar", function(msg)
  18.         --cancel();
  19.         print("interaction." .. msg.data);
  20.         enterStateMachine("interaction." .. msg.data);
  21.     end )
  22.     
  23.     onMsg("enterStateMachine", function(msg)
  24.         print("enterStateMachine :" .. msg.data);
  25.         enterStateMachine(msg.data);
  26.     end )
  27.  
  28.     
  29.     -- emotion pose messages
  30.     onMsg("emoThink", function(msg)
  31.         print("think");
  32.         setState("think");        
  33.     end )
  34.     
  35.     onMsg("emoHungry", function(msg)
  36.         print("hungry");
  37.         setState("hungry");        
  38.     end )
  39.     
  40.     onMsg("emoYawn", function(msg)
  41.         print("yawn");
  42.         setState("yawn");        
  43.     end )
  44.     
  45.     onMsg("emoHygiene", function(msg)
  46.         print("Elaine hygiene");
  47.         setState("hygiene");        
  48.     end )
  49.     
  50.     onMsg("emoSwing", function(msg)
  51.         print("swing");
  52.         setState("swing");        
  53.     end )
  54.     
  55.     onMsg("emoHappy", function(msg)
  56.         print("happy");
  57.         setState("happy");        
  58.     end )
  59.     
  60.     onMsg("emoFlirt", function(msg)
  61.         print("flirt");
  62.         storeData("flirtChar", msg.sender);
  63.         setState("flirt");        
  64.     end )
  65.     
  66.     onMsg("emoRefuse", function(msg)
  67.         print("refuse");
  68.         setState("refuse");        
  69.     end )
  70.     
  71.     onMsg("emoRefuseChar", function(msg)
  72.         print("onMsg emoRefuseChar");
  73.         storeData("refuseChar", msg.sender);
  74.         setState("refuseChar");        
  75.     end )
  76.     
  77.     onMsg("emoShameChar", function(msg)
  78.         print("onMsg emoShameChar");
  79.         storeData("shameChar", msg.sender);
  80.         setState("shameChar");        
  81.     end )
  82.     
  83.     onMsg("emoShameNackedChar", function(msg)
  84.         print("onMsg emoShameNackedChar");
  85.         storeData("shameChar", msg.sender);
  86.         setState("shameNackedChar");        
  87.     end )
  88.     
  89.     
  90.     onMsg("emoYouSmell", function(msg)
  91.         print("you smell");
  92.         storeData("smellChar", msg.sender);
  93.         setState("youSmell");        
  94.     end )
  95.     
  96.     onMsg("goAway", function(msg)
  97.         print("onMsg goAway(walk)");
  98.         
  99.         if (isWalking()) then return end;
  100.         
  101.         local minDist = 1.5;
  102.         local maxDist = 3.0;
  103.         local dataNum = tonumber(msg.data)
  104.         if (dataNum) then
  105.             minDist = dataNum;
  106.             maxDist = dataNum * 2;
  107.         end
  108.         
  109.         local target = getParent().findPointNear(minDist, maxDist);
  110.         if (target) then
  111.             print("goAway min dist " .. minDist);
  112.             getParent().queueWalkActionPoint("pm_walk", target, true);
  113.         else
  114.             print("goAway no target");
  115.         end
  116.     end )
  117.     
  118.     
  119.     -- stand : walk returns into this state -> fast fading
  120.     state("stand")
  121.         onEnter(function(msg)
  122.             print("stand " .. getParent().getCharacterName())
  123.             -- mission test
  124.             getParent().getGameObjectServer().mission.sendMsgThis("checkComplete");
  125.             setPose(archize(getParent(), "stand1"));
  126.             sendDelayedMsgThis("complete", STAND_POSE_COMPLETE_TIME);
  127.             
  128.         end )
  129.         
  130.         onMsg("complete", function(msg)
  131.             actionComplete();
  132.         end )    
  133.         
  134.         onMsg("end", function(msg)
  135.             setDelayedState("stand2", random(1000, 3000));
  136.             --actionComplete();
  137.         end )    
  138.  
  139.     -- same as stand but longer fadetime
  140.     state("stand1")
  141.         onEnter(function(msg)
  142.             print("stand1 " .. getParent().getCharacterName())
  143.             -- mission test
  144.             getParent().getGameObjectServer().mission.sendMsgThis("checkComplete");
  145.             --setPose("standElaine");
  146.             print("stand1 anim: " .. archize(getParent(), "stand1"));
  147.             startAnimation(archize(getParent(), "stand1"), false, 1.0, STAND_POSE_FADE_TIME);
  148.             
  149.             sendDelayedMsgThis("complete", STAND_POSE_COMPLETE_TIME);
  150.             
  151.         end )
  152.         
  153.         onMsg("complete", function(msg)
  154.             actionComplete();
  155.         end )    
  156.  
  157.         onMsg("end", function(msg)
  158.             setDelayedState("stand" .. randomExclude(1, 4, {1}), random(1000, 3000));
  159.         end )    
  160.  
  161.     state("stand2")
  162.         onEnter(function(msg)
  163.             print("stand2 " .. getParent().getCharacterName())
  164.             --setPose("stand2Elaine");
  165.             print("stand2 anim: " .. archize(getParent(), "stand2"));
  166.             startAnimation(archize(getParent(), "stand2"), false, 1.0, STAND_POSE_FADE_TIME);
  167.             sendDelayedMsgThis("complete", STAND_POSE_COMPLETE_TIME);
  168.             
  169.         end )
  170.         
  171.         onMsg("complete", function(msg)
  172.             actionComplete();
  173.         end )    
  174.         
  175.         onMsg("end", function(msg)
  176.             setDelayedState("stand" .. randomExclude(1, 4, {2}), random(1000, 3000));
  177.         end )    
  178.  
  179.     state("stand3")
  180.         onEnter(function(msg)
  181.             print("stand3 " .. getParent().getCharacterName())
  182.             --setPose("stand3Elaine");
  183.             print("stand3 anim: " .. archize(getParent(), "stand3"));
  184.             startAnimation(archize(getParent(), "stand3"), false, 1.0, STAND_POSE_FADE_TIME);
  185.             sendDelayedMsgThis("complete", STAND_POSE_COMPLETE_TIME);
  186.             
  187.         end )
  188.         
  189.         onMsg("complete", function(msg)
  190.             actionComplete();
  191.         end )    
  192.         
  193.         onMsg("end", function(msg)
  194.             setDelayedState("stand" .. randomExclude(1, 4, {3}), random(1000, 3000));
  195.         end )    
  196.         
  197.     state("stand4")
  198.         onEnter(function(msg)
  199.             print("stand4 " .. getParent().getCharacterName())
  200.             --setPose("stand4Elaine");
  201.             print("stand4 anim: " .. archize(getParent(), "stand4"));
  202.             startAnimation(archize(getParent(), "stand4"), false, 1.0, STAND_POSE_FADE_TIME);
  203.             sendDelayedMsgThis("complete", STAND_POSE_COMPLETE_TIME);
  204.             
  205.         end )
  206.         
  207.         onMsg("complete", function(msg)
  208.             actionComplete();
  209.         end )    
  210.         
  211.         onMsg("end", function(msg)
  212.             setDelayedState("stand" .. randomExclude(1, 4, {4}), random(1000, 3000));
  213.         end )
  214.         
  215.         
  216.         
  217.         
  218.         
  219.     state("think")
  220.         onEnter(function(msg)
  221.             print("setPose(emoThink)");
  222.             setPose("emoThink");
  223.             sendDelayedMsgThis("complete", EMO_POSE_COMPLETE_TIME);            
  224.         end )
  225.         
  226.         onMsg("complete", function(msg)
  227.             this.actionComplete();
  228.         end )    
  229.                         
  230.         onMsg("end", function(msg)
  231.             setState("stand");
  232.         end )    
  233.         
  234.     state("hungry")
  235.         onEnter(function(msg)
  236.             setPose("emoHungry");
  237.             this.actionComplete();            
  238.         end )
  239.         
  240.         onMsg("end", function(msg)
  241.             setState("stand");
  242.         end )
  243.             
  244.     state("yawn")
  245.         onEnter(function(msg)
  246.             setPose("emoYawn");
  247.             this.actionComplete();            
  248.         end )
  249.         
  250.         onMsg("end", function(msg)
  251.             setState("stand");
  252.         end )    
  253.         
  254.     state("hygiene")
  255.         onEnter(function(msg)
  256.             setPose("emoHygiene");
  257.             this.actionComplete();            
  258.         end )
  259.         
  260.         onMsg("end", function(msg)
  261.             setState("stand");
  262.         end )
  263.             
  264.     state("swing")
  265.         onEnter(function(msg)
  266.             setPose("emoSwingArms");
  267.             this.actionComplete();            
  268.         end )
  269.         
  270.         onMsg("end", function(msg)
  271.             setState("stand");
  272.         end )    
  273.         
  274.     state("happy")
  275.         onEnter(function(msg)
  276.             setPose("emoHappy");
  277.             this.actionComplete();            
  278.         end )
  279.         
  280.         onMsg("end", function(msg)
  281.             setState("stand");
  282.         end )    
  283.         
  284.     state("flirt")
  285.         onEnter(function(msg)
  286.             local partner = getStateObjectFromID(retrieveData("flirtChar"));              
  287.             if (partner) then
  288.                 turnToGameObject(partner)
  289.                 setPose("emoFlirt");
  290.                 this.actionComplete();        
  291.             else
  292.                 print("flirtChar not found");
  293.                 setState("stand");
  294.             end
  295.         end )
  296.         
  297.         onMsg("end", function(msg)
  298.             setState("stand");
  299.         end )    
  300.         
  301.     state("refuseChar")
  302.         onEnter(function(msg)
  303.             print("refuseChar onEnter");
  304.             local partner = getStateObjectFromID(retrieveData("refuseChar"));              
  305.             if (partner) then
  306.                 turnToGameObject(partner)
  307.                 setPose("emoRefuse");
  308.                 this.actionComplete();    
  309.             else
  310.                 print("refuseChar not found");
  311.                 setState("stand");
  312.             end
  313.         end )
  314.         
  315.         onMsg("end", function(msg)
  316.             setState("stand");
  317.         end )
  318.         
  319.         
  320.     state("shameChar")
  321.         onEnter(function(msg)
  322.             print("state shameChar");
  323.             local partner = getStateObjectFromID(retrieveData("shameChar"));              
  324.             --getOtherCharcter(getParent());
  325.             if (partner) then
  326.                 turnToGameObject(partner);
  327.                 setPose("emoShy");
  328.                 getParent().setEmoticon(EMOTICON_SHY, EMOTICON_DELAY);
  329.                 --this.actionComplete();    
  330.             else
  331.                 print("shameChar not found");
  332.                 setState("stand");
  333.                 return
  334.             end
  335.             this.actionComplete();
  336. --            sendDelayedMsgThis("complete", SHY_POSE_COMPLETE_TIME);            
  337.         end )
  338.         
  339. --        onMsg("complete", function(msg)
  340. --            actionComplete();
  341. --        end )    
  342.         
  343.         onMsg("end", function(msg)
  344.             setState("stand");
  345.         end )
  346.         
  347.         
  348.     state("shameNackedChar")
  349.         onEnter(function(msg)
  350.             print("state shameChar");
  351.             local partner = getStateObjectFromID(retrieveData("shameChar"));              
  352.             --getOtherCharcter(getParent());
  353.             if (partner) then
  354.                 turnToGameObject(partner);
  355.                 setPose("emoShyNacked");
  356.                 getParent().setEmoticon(EMOTICON_SHY, EMOTICON_DELAY);
  357.                 --this.actionComplete();            
  358.             else
  359.                 print("shameChar not found");
  360.                 setState("stand");
  361.                 return
  362.             end
  363.             sendDelayedMsgThis("complete", SHY_POSE_COMPLETE_TIME);            
  364.         end )
  365.         
  366.         onMsg("complete", function(msg)
  367.             actionComplete();
  368.         end )    
  369.         
  370.         onMsg("end", function(msg)
  371.             local other, result = getDisturbingChar(getParent(), "showNaked")
  372.             if testCancel() or (not other) then
  373.                 setState("stand");
  374.             else
  375.                 if (not urgentOutfitChange(getParent())) then
  376.                     setPose("emoShyNackedLoop");
  377.                     getParent().setEmoticon(EMOTICON_SHY, EMOTICON_DELAY);
  378.                     sendDelayedMsgThis("complete", SHY_POSE_COMPLETE_TIME);            
  379.                 end
  380.             end
  381.         end )
  382.         
  383.         
  384.         
  385.     state("refuse")
  386.         onEnter(function(msg)
  387.             setPose("emoRefuse");
  388.             this.actionComplete();            
  389.         end )
  390.         
  391.         onMsg("end", function(msg)
  392.             setState("stand");
  393.         end )    
  394.             
  395.         
  396.     state("youSmell")
  397.         onEnter(function(msg)
  398.             --local partner = getOtherCharcter(getParent());
  399.             local partner = getStateObjectFromID(retrieveData("smellChar"));              
  400.             if (partner) then
  401.                 turnToGameObject(partner)
  402.                 setPose("emoYouSmell");
  403.                 this.actionComplete();        
  404.             else
  405.                 print("smellChar not found");
  406.                 setState("stand");
  407.             end
  408.         end )
  409.         
  410.         onMsg("end", function(msg)
  411.             setState("stand");
  412.         end )
  413.         
  414.                 
  415. --    state("goAway")
  416. --        onEnter(function(msg)
  417. --            print("goAway onEnter");
  418. --            local target = getParent().findPointNear(2.0, 5.0);
  419. --            if (target) then
  420. --                if (not walkToActionPoint(target)) then
  421. --                    print("no path");
  422. --                end
  423. --            else
  424. --                print("no target");
  425. --            end
  426. --        end )
  427.         
  428.             
  429. --    state("goAway")
  430. --        onEnter(function(msg)
  431. --            print("goAway onEnter");
  432. --            local target = getParent().findPointNear(2.0, 5.0);
  433. --            if (target) then
  434. --                getParent().queueWalkActionPoint("pm_walk", target, true);
  435. --            else
  436. --                print("no target");
  437. --            end
  438. --        end )
  439.             
  440.             
  441.         
  442.     -- walk
  443.     state("walk")
  444.         onEnter(function(msg)
  445.             print("walk onEnter " .. getParent().getCharacterName());
  446.             -- if distance to walk is greater 4m, run
  447.             if isRunDistance() then
  448.                 setState("runRFF-runLFF");
  449.             else
  450.                 --startWalk("stand-walkLFF-Elaine", "stand-walkLFF-Elaine");
  451.                 local c = getParent();
  452.                 startWalk(archizeWalk(c, "stand-walkLFF-"), archizeWalk(c, "stand-walkLFF-"), WALK_SPEEDUP);
  453.             end
  454.         end )
  455.  
  456.         onMsg("next", function(msg)
  457.             if testCancel() then
  458.                 stopWalk();
  459.                 nextAction();
  460.             else
  461.                 setState("walkLFF-walkRFF");
  462.             end
  463.         end )    
  464.         
  465.         onMsg("end", function(msg)
  466.             nextAction();
  467.             --notify mission
  468.             getStateObjectFromID(msg.sender).getParent().sendMsg("arrived",getParent().getGameObjectServer().mission);
  469.         end )    
  470.  
  471.     state("walkRFF-walkLFF")
  472.         onEnter(function(msg)
  473.             if isRunDistance() then
  474.                 setState("runRFF-runLFF");
  475.             else
  476.                 --startWalk("walkRFF-walkLFF-Elaine", "walkRFF-stand-Elaine");
  477.                 local c = getParent();
  478.                 startWalk(archizeWalk(c, "walkRFF-walkLFF-"), archizeWalk(c, "walkRFF-stand-"), WALK_SPEEDUP);
  479.                 createDirt(DIRT_FOOTSTEP, WALK_DIRT_SIZE, WALK_DIRT_PROBABILITY);
  480.                 makeStepSound();
  481.             end
  482.         end )
  483.  
  484.         onMsg("next", function(msg)
  485.             if testCancel() then
  486.                 stopWalk();
  487.                 nextAction();
  488.             else
  489.                 setState("walkLFF-walkRFF");
  490.             end
  491.         end )    
  492.         
  493.         onMsg("end", function(msg)
  494.             nextAction();
  495.             --notify mission
  496.             getStateObjectFromID(msg.sender).getParent().sendMsg("arrived",getParent().getGameObjectServer().mission);
  497.         end )    
  498.  
  499.     state("walkLFF-walkRFF")
  500.         onEnter(function(msg)
  501.             --startWalk("walkLFF-walkRFF-Elaine", "walkLFF-stand-Elaine");
  502.             local c = getParent();
  503.             startWalk(archizeWalk(c, "walkLFF-walkRFF-"), archizeWalk(c, "walkLFF-stand-"), WALK_SPEEDUP);
  504.             makeStepSound();
  505.         end )
  506.  
  507.         onMsg("next", function(msg)
  508.             if testCancel() then
  509.                 stopWalk();
  510.                 nextAction();
  511.             else
  512.                 setState("walkRFF-walkLFF");
  513.             end
  514.         end )    
  515.         
  516.         onMsg("end", function(msg)
  517.             nextAction();
  518.             --notify mission
  519.             getStateObjectFromID(msg.sender).getParent().sendMsg("arrived",getParent().getGameObjectServer().mission);
  520.         end )    
  521.  
  522.     -- run
  523.     state("runRFF-runLFF")
  524.         onEnter(function(msg)
  525.             --startWalk("runRFF-runLFF-Elaine", "walkRFF-stand-Elaine");
  526.             local c = getParent();
  527.             startWalk(archizeRun(c, "runRFF-runLFF-"), archizeWalk(c, "walkRFF-stand-"), RUN_SPEEDUP);
  528.             createDirt(DIRT_FOOTSTEP, WALK_DIRT_SIZE, WALK_DIRT_PROBABILITY);
  529.             makeStepSound();
  530.         end )
  531.  
  532.         onMsg("next", function(msg)
  533.             if testCancel() then
  534.                 stopWalk();
  535.                 nextAction();
  536.             else
  537.                 setState("runLFF-runRFF");
  538.             end
  539.         end )    
  540.         
  541.         onMsg("end", function(msg)
  542.             nextAction();
  543.             --notify mission
  544.             getStateObjectFromID(msg.sender).getParent().sendMsg("arrived",getParent().getGameObjectServer().mission);
  545.         end )    
  546.  
  547.     state("runLFF-runRFF")
  548.         onEnter(function(msg)
  549.             --startWalk("runLFF-runRFF-Elaine", "walkLFF-stand-Elaine");
  550.             local c = getParent();
  551.             startWalk(archizeRun(c, "runLFF-runRFF-"), archizeWalk(c, "walkLFF-stand-"), RUN_SPEEDUP);
  552.             createDirt(DIRT_FOOTSTEP, WALK_DIRT_SIZE, WALK_DIRT_PROBABILITY);
  553.             makeStepSound();
  554.         end )
  555.  
  556.         onMsg("next", function(msg)
  557.             if testCancel() then
  558.                 stopWalk();
  559.                 nextAction();
  560.             else
  561.                 setState("runRFF-runLFF");
  562.             end
  563.         end )    
  564.         
  565.         onMsg("end", function(msg)
  566.             nextAction();
  567.             --notify mission
  568.             getStateObjectFromID(msg.sender).getParent().sendMsg("arrived",getParent().getGameObjectServer().mission);
  569.         end )    
  570.     
  571.         
  572. endStateMachine()
  573.